import request from "./request"

export const getFreeDoctor = async ()=>{
  let ret = await request({
    url:"/staff/online/find_by_role",
    method:"GET",
    data:{
      role:"doctor"
    }
  })

  let doctorArr = ret.data
  doctorArr.sort((a,b)=>{
    return a.toDoTasks - b.toDoTasks
  })

  return doctorArr[0];
}

export const updateDoctorToDoTasks = async (id,operation)=>{
  return await request({
    url:"/staff/update/to_do_tasks",
    method:"POST",
    data:{
      id,
      operation
    }
  })
}

export const getStaffInfo = async id =>{
  let ret = await request({
    url:"/staff/find_by_id",
    method:"GET",
    data:{
      id
    }
  })

  if(ret.code == 200){
    return ret.data
  }
}